#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time: 2022/9/15 17:57
# @Author: 刘航
# @Email: xxx@gmail.com
# @File：customer_page.py
"""
客户界面
"""
from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select
class CustomerPage(BasePage):

    add_cust_btn_locator = (By.XPATH,"/html/body/div[5]/div[2]/div[1]/div/a")
    add_cust_status_locator = (By.CSS_SELECTOR,".alert")
    cust_pool_locator = (By.CSS_SELECTOR,".nav-tabs > li:nth-child(2) > a:nth-child(1)")
    modify_cust_locator = (By.CSS_SELECTOR,".table > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(12) > a:nth-child(2)")
    first_cust_industry_locator = (By.CSS_SELECTOR,'.table > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(4)')
    select_industry_locator = (By.CSS_SELECTOR,"#field")
    search_locator = (By.ID,"search")
    dosearch_locator = (By.ID,'dosearch')
    first_cust_name_locator = (By.CSS_SELECTOR,".table > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(3)")
    cust_care_locator = (By.CSS_SELECTOR,".nav-tabs > li:nth-child(4) > a:nth-child(1)")
    select_delete_locator = (By.CSS_SELECTOR,".table > tbody:nth-child(3) > tr:nth-child(1) > td:nth-child(1) > input:nth-child(1)")
    action_delete_locator = (By.CSS_SELECTOR,"div.pull-left:nth-child(1) > a:nth-child(1)")
    delete_locator = (By.CSS_SELECTOR,"#delete")
    view_delete_locator = (By.CSS_SELECTOR,".alert")
    def add_cust_btn(self):
        """客户页面新建客户按钮"""
        self.driver.find_element(*self.add_cust_btn_locator).click()
    def add_cust_status(self):
        """添加客户提示"""
        data = self.driver.find_element(*self.add_cust_status_locator).text
        return data
    def cust_pool(self):
        """客户池"""
        self.driver.find_element(*self.cust_pool_locator).click()
    def modify_cust(self):
        """编辑按钮"""
        self.driver.find_element(*self.modify_cust_locator).click()
    def first_cust_industry(self):
        """获取第一位客户的行业"""
        data = self.driver.find_element(*self.first_cust_industry_locator).text
        return data
    def select_industry(self,select_industry):
        """操作搜索下拉框"""
        select_selenium = self.driver.find_element(*self.select_industry_locator)
        Select(select_selenium).select_by_visible_text(select_industry)

    def search_cust_industry(self,industry):
        """操作搜索框"""
        self.driver.find_element(*self.search_locator).send_keys(industry)
    def dosearch_cust(self):
        """点击搜索"""
        self.driver.find_element(*self.dosearch_locator).click()
    def first_cust_name(self):
        """第一位客户的名称"""
        data = self.driver.find_element(*self.first_cust_name_locator).text
        return data
    def cust_care(self):
        """客户关怀"""
        self.driver.find_element(*self.cust_care_locator).click()
    def select_delete_cust(self):
        """选择要删除的"""
        self.driver.find_element(*self.select_delete_locator).click()
    def action_delete_action(self):
        """操作删除下拉框"""
        self.driver.find_element(*self.action_delete_locator).click()  # 操作删除
    def click_delete_btn(self):
        """点击删除按钮"""
        self.driver.find_element(*self.delete_locator).click()
        self.driver.switch_to.alert.accept()
    def view_delete_status(self):
        """查看删除状态"""
        actual = self.driver.find_element(*self.view_delete_locator).text  # 实际结果
        return actual